//
//  AppDelegate.m
//  TextApplication
//
//  Created by dllo on 16/8/26.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "AppDelegate.h"
#import "TAMacro.h"
#import "MainViewController.h"
#import "LoginViewController.h"
#import "LaunchIntroductionView.h"
#import "ClassifyViewController.h"
#import "CDPGifScrollView.h"

#import "UMSocial.h"
#import "UMSocialSinaSSOHandler.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"

BOOL isOut = NO;

@interface AppDelegate () <UIApplicationDelegate, UIScrollViewDelegate>
@property (nonatomic, strong) CDPGifScrollView *gifScrollView;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == FALSE) {
        //调用其他SDK，例如支付宝SDK等
    }
    return result;

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//     Override point for customization after application launch.
    
    // 记录登录状态
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *myDic = [userDefaults dictionaryForKey:@"myDic"];
    NSLog(@"%@", myDic);
//    NSNotification *secNotice = [NSNotification notificationWithName:@"sendUserData" object:nil userInfo:@{@"user": myDic}];
//    [[NSNotificationCenter defaultCenter] postNotification:secNotice];
    
    // 填写新浪微博Appkey
    [UMSocialData setAppKey:@"57e3a228e0f55ace8d003d06"];
    // 新浪微博 第一个参数为新浪appkey,第二个参数为新浪secret，第三个参数是新浪微博回调地址，这里必须要和你在新浪微博后台设置的回调地址一致。
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"2646202882" secret:@"41ab42d4915e6edd82596d5762ebd17b" RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
//    // 微信 这里要填的是微信的appKey(要填写的内容是在微信开发平台获取的信息)
//    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
//    // qq分享 (需要到qq开放平台注册)
//    [UMSocialQQHandler setQQWithAppId:@"1105715050" appKey:@"Hr6BXR0eyH8tDAkK" url:@"http://www.umeng.com/social"];
    
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    self.window = [[UIWindow alloc] initWithFrame:SCREEN_RECT];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
   
    MainViewController *tabBar = [MainViewController new];
    
    self.window.rootViewController = tabBar.tabBarViewController;
    // 只出现一次
    NSUserDefaults *user = [[NSUserDefaults alloc] init];
    
    if (![user objectForKey:@"lP"]) {
        NSMutableArray *picArray = [NSMutableArray array];
        for (NSInteger i = 1; i < 6; i++) {
            NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%ld", i] ofType:@"gif"];
            [picArray addObject:path];
        }
        self.gifScrollView = [[CDPGifScrollView alloc] initWithGifImageArr:picArray andFrame:self.window.bounds];
        self.gifScrollView.delegate = self;
        [self.window addSubview:self.gifScrollView];
        
        [user setObject:@"perpect" forKey:@"lP"];
    }
    
        return YES;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView.contentOffset.x == self.window.bounds.size.width * 4) {
        [UIView animateWithDuration:2 animations:^{
            self.gifScrollView.alpha = 0;
        } completion:^(BOOL finished) {
            [self.gifScrollView removeFromSuperview];
        }];
    }
}




- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
